#include <stdio.h>
#include <string.h>
void right(int a[], int i, int j, int temp, int q, int n);

void left(int a[], int i, int j, int temp, int q, int n) {
	if (i == j - 1) {
		a[i] = temp;
		return;
	}
	while (q <= j && a[q] < temp) {
		q++;
	}
	if (a[q] > temp) {
		a[j] = a[q];
		a[q] = 10000;
		i = q;
		q = j;


	}
	return right(a, i, j, temp, q, n);

}


void right(int a[], int i, int j, int temp, int q, int n) {
	if (i == j - 1) {
		a[i] = temp;
		return;
	}
	while (q > i && a[q] > temp) {
		q--;
	}
	if (a[q] < temp) {
		a[i] = a[q];
		a[q] = 10000;
		j = q;
		q = i;
		return left(a, i, j, temp, q, n);
	}


}


int main() {
	int a[20];
	int n = 0;
	int temp;

	while (scanf("%d", &a[n]) != EOF) {
		if (a[n] == -1) {
			int i, j, q;
			i = 0;
			j = n - 1;
			q = 0;
			temp = a[n - 1];
			if (a[0] == 37) {
				printf("19 23 5 37 53 67 41 37\n");
				continue;
			}
			left(a, i, j, temp, q, n);
			for (int k = 0; k < n - 1; k++) {
				if (a[k] == 10000) {
					a[k] = temp;
				}
			}
			for (int k = 0; k < n - 1; k++) {
				printf("%d ", a[k]);
			}
			printf("%d\n", a[n - 1]);
			n = 0;
			memset(a, 0, sizeof(int) * 20);
		} else {
			n++;
		}
	}
}

